home *** CD-ROM | disk | FTP | other *** search
- // GETINFO SCRIPTING
- // Onet(PL) import, made by Cabal & Mirwoj
-
- (********************************************************
- * Film.Onet.pl movie information importation script *
- * (c) 2003 Cabal & Mirwoj *
- * based on Filmweb.pl version (c) 2002 Piotr Kardasz *
- * *
- * Works fine, but return nothing when movie does not *
- * exists on film.onet.pl *
- * Script does not affect original movie title [in *
- * order not to change it when wrong movie found, but *
- * it can be changed - just uncomment one line] *
- * *
- * For use with Ant Movie Catalog 3.2.1 *
- * www.ant.be.tf/moviecatalog ╖╖╖ www.buypin.com *
- ********************************************************)
-
- program Onet;
- var
- MovieName: string;
-
- procedure DelSpace(var Value: String);
- var
- FullValue: String;
- Counter: Integer;
- begin
- if Value <> '' then
- begin
- FullValue := FullValue + StrGet(Value, 1);
- for Counter := 2 to Length(Value) do
- begin
- if StrGet(Value, Counter) <> ' ' then
- FullValue := FullValue + StrGet(Value, Counter)
- else
- if StrGet(FullValue, Length(FullValue)) <> ' ' then
- FullValue := FullValue + ' ';
- end;
- Value := FullValue;
- end
- end;
-
- procedure DecodeHTML(var Value: String);
- var
- FullValue, CharCode: String;
- Counter: Integer;
- begin
- if Value <> '' then
- begin
- FullValue := '';
- Counter := 1;
- repeat
- if StrGet(Value, Counter) <> '&' then
- begin
- CharCode := copy(Value, Counter, 1);
- case CharCode of
- '▒': CharCode := '╣';
- '╢': CharCode := '£';
- '╝': CharCode := 'ƒ';
- 'ª': CharCode := 'î';
- 'í': CharCode := 'Ñ';
- '¼': CharCode := 'Å';
- end;
- FullValue := FullValue + CharCode;
- Counter := Counter + 1;
- end
- else
- begin
- CharCode := copy(Value, Counter, 7);
- case CharCode of
- 'ą': FullValue := FullValue + '╣';
- 'ć': FullValue := FullValue + 'µ';
- 'ę': FullValue := FullValue + 'Ω';
- 'ł': FullValue := FullValue + '│';
- 'ń': FullValue := FullValue + '±';
- 'ó': FullValue := FullValue + '≤';
- 'ś': FullValue := FullValue + '£';
- 'ź': FullValue := FullValue + 'ƒ';
- 'ż': FullValue := FullValue + '┐';
- 'Ą': FullValue := FullValue + 'Ñ';
- 'Ć': FullValue := FullValue + '╞';
- 'Ę': FullValue := FullValue + '╩';
- 'Ł': FullValue := FullValue + 'ú';
- 'Ń': FullValue := FullValue + '╤';
- 'Ó': FullValue := FullValue + '╙';
- 'Ś': FullValue := FullValue + 'î';
- 'Ź': FullValue := FullValue + 'Å';
- 'Ż': FullValue := FullValue + '»';
- else
- FullValue := FullValue + CharCode;
- end;
- Counter := Counter + 7;
- end;
- until Counter > Length(Value);
- HTMLDecode(FullValue);
- Value := FullValue;
- end
- end;
-
- procedure StripHTML(var sString: string);
- var i:integer;
- sTemp: string;
- bOutHTML: boolean;
- cChar: char;
- begin
- sTemp := sString;
- sString := '';
- bOutHTML := TRUE;
-
- for i :=1 to Length(sTemp) do
- begin
- cChar := Copy(sTemp,i,1);
- if (cChar = '<') then bOutHTML := FALSE;
- if (bOutHTML) then
- sString := sString + cCHar;
- if (cChar = '>') then bOutHTML := TRUE;
- end;
- end;
-
- function CountStrings(sString: String; sWhat: String): Integer;
- var
- iCnt: Integer;
- iPos: Integer;
- begin
- iCnt := 0;
- iPos := Pos(sWhat, sString);
- while iPos > 0 do
- begin
- iCnt := iCnt + 1;
- sString := Copy(sString, iPos + 1, Length(sString));
- iPos := Pos(sWhat, sString);
- end;
- Result := iCnt;
- end;
-
- function RetrieveMovieTitle(sTitleBff: String): String;
- var
- iEndPos: Integer;
- begin
- iEndPos := Pos('</B>', sTitleBff);
- if iEndPos > 0 then
- Result := Copy(sTitleBff, 1, iEndPos - 1)
- else
- Result := '???';
-
- DecodeHTML(Result);
- HTMLRemoveTags(Result);
- end;
-
- function AddMoviesTitles(Page: TStringList; iCnt: Integer): Integer;
- var
- MovieTitle: string;
- i, iPos: Integer;
- cChar: Char;
- iNumLen: Integer;
- sNum: String;
- sPage: String;
- oPage: TStringList;
-
- begin
- sPage := Page.Text;
-
- if (iCnt = 1) then
- begin
- iPos := Pos(',film.html" class=', sPage) - 1;
- MovieTitle := RetrieveMovieTitle(Copy(sPage, iPos + 24, 200));
-
- cChar := Copy(sPage, iPos, 1);
- iNumLen := 0;
- while (cChar >= '0') and (cChar <= '9') do
- begin
- iNumLen := iNumLen + 1;
- iPos := iPos - 1;
- cChar := Copy(sPage, iPos, 1);
- end;
- sNum := Copy(sPage, iPos + 1, iNumLen);
- oPage := TStringList.Create;
- oPage.Text := GetPage('http://film.onet.pl/' + sNum +',film.html');
- AnalyzeMoviePage(oPage, 'http://film.onet.pl/' + sNum +',film.html')
- end
-
- else
-
- begin
- PickTreeAdd('Znaleziono filmy:', '');
- for i := 1 to iCnt do
- begin
- iPos := Pos(',film.html" class=', sPage) - 1;
- MovieTitle := RetrieveMovieTitle(Copy(sPage, iPos + 24, 200));
-
- cChar := Copy(sPage, iPos, 1);
- iNumLen := 0;
- while (cChar >= '0') and (cChar <= '9') do
- begin
- iNumLen := iNumLen + 1;
- iPos := iPos - 1;
- cChar := Copy(sPage, iPos, 1);
- end;
- sNum := Copy(sPage, iPos + 1, iNumLen);
- //ShowMessage('URL: http://film.onet.pl/' + sNum +',film.html');
- PickTreeAdd(MovieTitle, 'http://film.onet.pl/' + sNum +',film.html');
-
- sPage := Copy(sPage, iPos + 50, Length(sPage));
- end;
- end;
- end;
-
- procedure AnalyzePage(Address: string);
- var
- Page: TStringList;
- FilmCount, iCnt: Integer;
- begin
- Page := TStringList.Create;
- Page.Text := GetPage(Address);
- if pos('Wynik wyszukiwania', Page.Text) = 0 then
- AnalyzeMoviePage(Page, Address)
- else
- begin
- iCnt := CountStrings(Page.Text, ',film.html" class=');
- if(iCnt > 0) then
- begin
- if(iCnt = 1) then AddMoviesTitles(Page, iCnt)
- else
- begin
- PickTreeClear;
- AddMoviesTitles(Page, iCnt);
- if PickTreeExec(Address) then
- AnalyzePage(Address);
- end;
- end;
- end;
- Page.Free;
- end;
-
- procedure AnalyzeMoviePage(Page: TStringList; sURL: String);
- var
- sPage, sValue, sTemp, sPosterURL, sPicUrl: string;
- iPos, iStartPos, iEndPos, iLength: Integer;
- cChar: char;
- begin
- sPage := Page.Text;
-
- // Page URL
- SetField(fieldURL, sURL);
-
- // Polish title
- iStartPos := pos('class=tyw', sPage) + 10;
- sPage := Copy(sPage, iStartPos, Length(sPage));
- iEndPos := pos('TD', sPage) - 3;
- sValue := Copy(sPage, 1, iEndPos);
- DecodeHTML(sValue);
- SetField(fieldTranslatedTitle, sValue);
- sPage := Copy(sPage, iEndPos, Length(sPage));
-
- // Oryginal title
- iStartPos := pos('<B>', sPage) + 3;
- iEndPos := pos('</B>', sPage);
- if iStartPos < pos(' (', sPage) then
- begin
- iLength := iEndPos - iStartPos;
- sValue := Copy(sPage, iStartPos, iLength);
- DecodeHTML(sValue);
- //Uncomment this line if you want to save found original title
- //SetField(fieldOriginalTitle, sValue);
- end;
-
- // Country
- iStartPos := pos(' (', sPage) + 2;
- sPage := Copy(sPage, iStartPos, Length(sPage));
- iEndPos := pos(')', sPage) - 7;
- sValue := Copy(sPage, 1, iEndPos);
- DecodeHTML(sValue);
- SetField(fieldCountry, sValue);
- sPage := Copy(sPage, iEndPos, Length(sPage));
-
- // Year of production
- iStartPos := pos(')', sPage) -5;
- sPage := Copy(sPage, iStartPos, Length(sPage));
- iEndPos := pos(')', sPage) - 1;
- sValue := Copy(sPage, 1, iEndPos);
- SetField(fieldYear, sValue);
- sPage := Copy(sPage, iEndPos, Length(sPage));
-
- // Category
- iStartPos := pos('<BR>', sPage) + 4;
- sPage := Copy(sPage, iStartPos, Length(sPage));
- iEndPos := pos('<BR>', sPage) - 1;
- sValue := Copy(sPage, 1, iEndPos);
- DecodeHTML(sValue);
- SetField(fieldCategory, sValue);
- sPage := Copy(sPage, iEndPos, Length(sPage));
-
- // Length
- iStartPos := pos('czas ', sPage) + 5;
- iEndPos := pos('min', sPage) - 1;
- iLength := iEndPos - iStartPos;
- sValue := Copy(sPage, iStartPos, iLength);
- SetField(fieldLength, sValue);
-
- // Director
- iStartPos := pos('yseria', sPage) + 19;
- sPage := Copy(sPage, iStartPos, Length(sPage));
- iEndPos := pos('Scenariusz', sPage) - 5;
- sValue := Copy(sPage, 1, iEndPos);
- StripHTML(sValue);
- DecodeHTML(sValue);
- SetField(fieldDirector, sValue);
- sPage := Copy(sPage, iEndPos, Length(sPage));
-
- {
- // Large picture, I'm not sure if this works
- // Uncommeht this section and comment Small picture if you want to download posters
- iStartPos := pos(',plakat.html', sPage);
- if (iStartPos > 0) then
- begin
- sValue := GetField(fieldComments) + ' Znaleznione plakaty: ';
- cChar := Copy(sPage, iStartPos, 1);
- while (cChar <> '"') do
- begin
- iStartPos := iStartPos - 1;
- iLength := iLength + 1;
- cChar := Copy(sPage, iStartPos, 1);
- end;
- iPos := 2;
- sPosterURL :='http://film.onet.pl/' + Copy(sPage, (iStartPos + 1), (iLength-1)) + ',plakat.html';
- sTemp := GetPage(sPosterURL);
- iStartPos := pos('IMG class=pic border=1 src="', sTemp) + 28;
- sTemp := Copy(sTemp, iStartPos, Length(sTemp));;
- iEndPos := pos('"', sTemp) - 1;
- sValue := sValue + 'http://film.onet.pl/' + Copy(sTemp, 1, iEndPos);
-
-
- SetField(fieldComments, sValue);
- end;
- }
- // Small picture
- iStartPos := pos('src=', sPage) + 5;
- sTemp := Copy(sPage, iStartPos, Length(sPage));
- iStartPos := pos('src="', sTemp) + 5;
- sTemp := Copy(sTemp, iStartPos, Length(sTemp));
- iEndPos := pos('"', sTemp)-1;
- sPicURL := 'http://film.onet.pl/' + Copy(sTemp, 1, iEndPos);
- GetPicture(sPicURL, False); // False = do not store picture externally ; store it in the catalog file
-
- // Actors
- iStartPos := pos('Obsada', sPage);
- sTemp := Copy(sPage, iStartPos, Length(sPage));
- iStartPos :=pos('<TABLE', sTemp);
- sTemp := Copy(sTemp, iStartPos, Length(sPage));
- iEndPos := pos('wiΩcej', sTemp) - 5;
- sValue := Copy(sTemp, 1, iEndPos);
- sValue := StringReplace(sValue, '</TR><TR>', ', ');
- StripHTML(sValue);
- DecodeHTML(sValue);
-
- iEndPos := Length(sValue);
- cChar := Copy(sValue, iEndPos, 1);
- while (cChar = ',') or (cChar = ' ') do
- begin
- iEndPos := iEndPos - 1;
- cChar := Copy(sValue, iEndPos, 1);
- end;
- sValue := Copy(sValue, 1, iEndPos);
- SetField(fieldActors, sValue);
-
- // Description
- iStartPos := pos('Tre', sPage);
- if (iStartPos > 0) then
- begin
- iStartPos := iStartPos + 5;
- sTemp := Copy(sPage, iStartPos, Length(sPage));
- iEndPos := pos('</DIV>', sTemp);
- sValue := Copy(sTemp, 1, iEndPos);
- StripHTML(sValue);
- DecodeHTML(sValue);
- SetField(fieldDescription, sValue);
- end
- else SetField(fieldDescription, 'Brak');
-
- DisplayResults;
- end;
-
-
- begin
- if CheckVersion(3,2,1) then
- begin
- MovieName := GetField(fieldOriginalTitle);
- if Input('Film.Onet.Pl Import by Cabal & Mirwoj', 'Podaj oryginalny tytu│ filmu:', MovieName) then
- begin
- AnalyzePage('http://film.onet.pl/filmoteka.html?O=1&S='+UrlEncode(MovieName));
- end;
- end
- else ShowMessage('Skrypt wymaga programu Ant Movie Catalog w wersji 3.2.1 lub nowszej');
- end.
-
-
-